home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / Fl_Overlay_Window.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  4.1 KB  |  145 lines

  1. //
  2. // "$Id: Fl_Overlay_Window.cxx,v 1.7 1999/01/07 19:17:24 mike Exp $"
  3. //
  4. // Overlay window code for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // A window using double-buffering and able to draw an overlay
  27. // on top of that.  Uses the hardware to draw the overlay if
  28. // possible, otherwise it just draws in the front buffer.
  29.  
  30. #include <config.h>
  31. #include <FL/Fl.H>
  32. #include <FL/Fl_Overlay_Window.H>
  33. #include <FL/fl_draw.H>
  34. #include <FL/x.H>
  35.  
  36. void Fl_Overlay_Window::show() {
  37.   Fl_Double_Window::show();
  38.   if (overlay_ && overlay_ != this) overlay_->show();
  39. }
  40.  
  41. void Fl_Overlay_Window::hide() {
  42.   Fl_Double_Window::hide();
  43. }
  44.  
  45. void Fl_Overlay_Window::flush() {
  46.   int erase_overlay = (damage()&FL_DAMAGE_OVERLAY);
  47.   clear_damage(damage()&~FL_DAMAGE_OVERLAY);
  48.   Fl_Double_Window::flush(erase_overlay);
  49.   if (overlay_ == this) draw_overlay();
  50. }
  51.  
  52. void Fl_Overlay_Window::resize(int X, int Y, int W, int H) {
  53.   Fl_Double_Window::resize(X,Y,W,H);
  54.   if (overlay_ && overlay_!=this) overlay_->resize(0,0,w(),h());
  55. }
  56.  
  57. Fl_Overlay_Window::~Fl_Overlay_Window() {
  58.   hide();
  59. //  delete overlay; this is done by ~Fl_Group
  60. }
  61.  
  62. #if !HAVE_OVERLAY
  63.  
  64. int Fl_Overlay_Window::can_do_overlay() {return 0;}
  65.  
  66. void Fl_Overlay_Window::redraw_overlay() {
  67.   overlay_ = this;
  68.   clear_damage(damage()|FL_DAMAGE_OVERLAY);
  69.   Fl::damage(FL_DAMAGE_CHILD);
  70. }
  71.  
  72. #else
  73.  
  74. extern XVisualInfo *fl_find_overlay_visual();
  75. extern XVisualInfo *fl_overlay_visual;
  76. extern Colormap fl_overlay_colormap;
  77. extern unsigned long fl_transparent_pixel;
  78. static GC gc;    // the GC used by all X windows
  79. extern uchar fl_overlay; // changes how fl_color(x) works
  80.  
  81. class _Fl_Overlay : public Fl_Window {
  82.   friend class Fl_Overlay_Window;
  83.   void flush();
  84.   void show();
  85. public:
  86.   _Fl_Overlay(int x, int y, int w, int h) :
  87.     Fl_Window(x,y,w,h) {deactivate();}
  88. };
  89.  
  90. int Fl_Overlay_Window::can_do_overlay() {
  91.   return fl_find_overlay_visual() != 0;
  92. }
  93.  
  94. void _Fl_Overlay::show() {
  95.   if (shown()) {Fl_Window::show(); return;}
  96.   fl_background_pixel = int(fl_transparent_pixel);
  97.   Fl_X::make_xid(this, fl_overlay_visual, fl_overlay_colormap);
  98.   fl_background_pixel = -1;
  99.   // find the outermost window to tell wm about the colormap:
  100.   Fl_Window *w = window();
  101.   for (;;) {Fl_Window *w1 = w->window(); if (!w1) break; w = w1;}
  102.   XSetWMColormapWindows(fl_display, fl_xid(w), &(Fl_X::i(this)->xid), 1);
  103. }
  104.  
  105. void _Fl_Overlay::flush() {
  106.   fl_window = fl_xid(this);
  107.   if (!gc) gc = XCreateGC(fl_display, fl_xid(this), 0, 0);
  108.   fl_gc = gc;
  109.   fl_overlay = 1;
  110.   Fl_Overlay_Window *w = (Fl_Overlay_Window *)parent();
  111.   Fl_X *i = Fl_X::i(this);
  112.   if (damage() != FL_DAMAGE_EXPOSE) XClearWindow(fl_display, fl_xid(this));
  113.   fl_clip_region(i->region); i->region = 0;
  114.   w->draw_overlay();
  115.   fl_overlay = 0;
  116. }
  117.  
  118. void Fl_Overlay_Window::redraw_overlay() {
  119.   if (!fl_display) return; // this prevents fluid -c from opening display
  120.   if (!overlay_) {
  121.     if (can_do_overlay()) {
  122.       Fl_Group::current(this);
  123.       overlay_ = new _Fl_Overlay(0,0,w(),h());
  124.       Fl_Group::current(0);
  125.     } else {
  126.       overlay_ = this;    // fake the overlay
  127.     }
  128.   }
  129.   if (shown()) {
  130.     if (overlay_ == this) {
  131.       clear_damage(damage()|FL_DAMAGE_OVERLAY);
  132.       Fl::damage(FL_DAMAGE_CHILD);
  133.     } else if (!overlay_->shown())
  134.       overlay_->show();
  135.     else
  136.       overlay_->redraw();
  137.   }
  138. }
  139.  
  140. #endif
  141.  
  142. //
  143. // End of "$Id: Fl_Overlay_Window.cxx,v 1.7 1999/01/07 19:17:24 mike Exp $".
  144. //
  145.